package com.ceadeal.admin.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.concurrent.TimeUnit;

/**
 * 功能描述: MVC配置
 *
 * 作者: Yzw
 * @date 2017-03-15 18:25:57
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    /**
     * 配置静态资源缓存策略
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/flash/**").addResourceLocations("classpath:/static/flash/").setCacheControl(CacheControl.maxAge(7, TimeUnit.DAYS));
        registry.addResourceHandler("/font/**").addResourceLocations("classpath:/static/font/").setCacheControl(CacheControl.maxAge(7, TimeUnit.DAYS));
        registry.addResourceHandler("/plugin/**").addResourceLocations("classpath:/static/plugin/").setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS));
        registry.addResourceHandler("/page/error/**").addResourceLocations("classpath:/static/page/error/").setCacheControl(CacheControl.maxAge(7, TimeUnit.DAYS));
        super.addResourceHandlers(registry);
    }
}
